// -- Lookup type
	// - Model
		Ext.define('LookupType', {
			extend: 'Ext.data.Model', 
			fields: [{
				name: 'id', 
				type: 'int', 
			}, {
				name : 'version',
				type : 'int'
			}, 'name', {
				name : 'createdDate',
				type : 'date'
			}, {
				name : 'updatedDate',
				type : 'date'
			}]
		});
	// - Store
		var lookupTypeStore = Ext.create('Ext.data.Store', {
			//autoDestroy: true,
			model: 'LookupType', 
			proxy: {
				type: 'ajax', 
				// batchActions: false, 
				api: {
	                read: 'dropdown/retrieveAll.json',
	                create: 'dropdown/save.json',
	                update: 'dropdown/save.json',
	                destroy: 'dropdown/remove.json'
				}, 
				reader: {
					type: 'json', 
					root: 'lookupTypes', 
					totalProperty: 'total',
					successProperty: 'success'
				}, 
				writer: {
					type: 'json',
	                writeAllFields: true,
	                root: 'lookupTypes', 
	                encode: false
				}
			}, 
			autoLoad: true, 
			autoSync: true
			
		});
		
		
		lookupTypeStore.on('add', function(store, records, index, options) {
			/* store.load(); */
		});
		
		lookupTypeStore.on('update', function(store, record, operation, options) {
			// alert('update');
			lookupTypeStore.load(); 
		});
		lookupTypeStore.on('remove', function(store, record, index, options) {
			var myAutoReload = new Ext.util.DelayedTask(function(){
				lookupTypeStore.load(); 
			});
			lookupTypeStore.delay(2000);  		
		});
		// create row editing plugin
		var lookupTypeRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
			clicksToMoveEditor : 1,
			autoCancel : false
		});
	// - Plugin

// -- Lookup
function loadDropdown() {
	// Create the Grid
	
	var lookupTypeGrid = Ext
	.create(
			'Ext.grid.Panel',
			{
				store : lookupTypeStore,
				renderTo : 'dropDownDiv',
				padding : 5,
				width : 600,
				//border: 0, 
				//height : 400,
				frame : false,
				forceFit: true,
				columns : [
						{
							header : 'ID',
							dataIndex : 'id'
						},
						{
							header : 'Name',
							dataIndex : 'name',

							editor : {
								allowBlank : false
							}
						},
						{
							header : 'Version',
							dataIndex : 'version'
						}],
				tbar : [ {
					text : 'Add Lookup Type',
					// action: 'save',
					handler : function() {
						lookupTypeRowEditing.cancelEdit();
						var lookupTypeRec = new LookupType({
							name : 'enter name'
						});
						lookupTypeStore.insert(0, lookupTypeRec);
						lookupTypeRowEditing.startEdit(0, 0);
					}
				}, {
					text : 'Remove LookupType',
					itemId : 'removeLookupType',
					handler : function() {
						var sm = lookupTypeGrid.getSelectionModel();
						lookupTypeRowEditing.cancelEdit();
						lookupTypeStore.remove(sm.getSelection());
						if (lookupTypeStore.getCount() > 0) {
							sm.select(0);
						}
					},
					disabled : true
				} ],
				plugins : [ lookupTypeRowEditing ],
				listeners : {
					'selectionchange' : function(view, records) {
						lookupTypeGrid.down('#removeLookupType').setDisabled(
								!records.length);
					}
				}
			});
	
}